package com.pattern.responsibility;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author qingshan
 * @since 2020-07-25 16:14
 */
public class Main {
    public static void main(String[] args) {

        Msg msg = new Msg();
        msg.setMsg("<stript>, 大家好，996, com.aoyama.test");
// -----------------------1.初步需求-----------------------------
//        String r = msg.getMsg();
//        r = r.replace("<", "[");
//        r = r.replace(">", "]");
//
//        r = r.replace("996", "955");
//        msg.setMsg(r);

// ------------------------2.----------------------------
//        List<Filter> filters = new ArrayList<Filter>();
//        filters.add(new HtmlFilter());
//        filters.add(new SensitiveFilter());
//
//        for (Filter f : filters){
//            f.doFilter(msg);
//        }

// ------------------------3.----------------------------
//        FilterChain filterChain = new FilterChain();
//        filterChain.addFilter(new HtmlFilter());
//        filterChain.addFilter(new SensitiveFilter());
//        new HtmlFilter().doFilter(msg);
//        new SensitiveFilter().doFilter(msg);

// ------------------------4.链式编程技巧----------------------------
//        FilterChain filterChain = new FilterChain();
//        filterChain.addFilter(new HtmlFilter()).addFilter(new SensitiveFilter());
//        filterChain.doFilter(msg);

// ------------------------4.1.添加第二个链处理----------------------------
//        FilterChain filterChain2 = new FilterChain();
//        filterChain2.addFilter(new HtmlFilter()).addFilter(new SensitiveFilter());
//        filterChain2.doFilter(msg);

// ------------------------5.两个链合并处理 即filterChain也实现filter接口----------------------------
        FilterChain filterChain = new FilterChain();
        filterChain.addFilter(new HtmlFilter()).addFilter(new SensitiveFilter());

        FilterChain filterChain2 = new FilterChain();
        filterChain2.addFilter(new HtmlFilter()).addFilter(new SensitiveFilter());
        filterChain.addFilter(filterChain);
        filterChain.doFilter(msg);

        System.out.println("=----=" + msg.getMsg());
    }
}

